﻿CREATE TRIGGER tri_Repossession
ON dbo.t_Repossession 
FOR INSERT,UPDATE
AS

IF @@ROWCOUNT = 0 RETURN

IF UPDATE(StatusID)BEGIN --[

DECLARE @CI int
EXEC @CI = sp__Context_SecurityOff 1

UPDATE R SET DateActive = dbo.StatusLog_Repo_FirstActiveDate(R.ID)
FROM t_Repossession R INNER JOIN inserted i ON R.ID = i.ID
LEFT OUTER JOIN deleted d ON i.ID = d.ID
WHERE d.StatusID IS NULL OR d.StatusID <> i.StatusID

EXEC sp__Context_SecurityOff @CI

END --]
